package com.jpa.lgt.controller;

import com.jpa.lgt.core.common.Result;
import com.jpa.lgt.entity.User;
import com.jpa.lgt.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.jws.WebParam;

/**
 * @author lgt
 * @time 2018/9/26
 * @description：
 */
@Controller
@RequestMapping("/user")
public class UserController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public String login(@RequestParam String account, @RequestParam String pwd, Model model) {
        User user = userService.userLogin(account, pwd);
        logger.info("account:" + account + ",pwd:" + pwd);
        if (user == null) {
            model.addAttribute("msg", "账号或者密码错误！");
            return "/login.html";
        }
        return "redirect:/index";
    }

    @RequestMapping("/index")
    public String index() {
        return "/index.html";
    }

    @RequestMapping("/loginPage")
    public String loginPage(Model model) {
        model.addAttribute("msg", "");
        return "/login.html";
    }


}
